package org.graduates.webapp.actions.course.json;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.graduates.webapp.actions.BaseAction;
import org.projects.graduates.domain.HomeworkComment;
import org.projects.graduates.domain.HomeworkHandin;

/**
 * 某个作业成绩的评论
 * @author Administrator
 *
 */

@Action(results = { @Result(name = "success", type = "json",params={"includeProperties",
		"success,comments,comments\\[\\d+\\]\\.id, comments\\[\\d+\\]\\.content, comments\\[\\d+\\]\\.time," +
		"comments\\[\\d+\\]\\.person, comments\\[\\d+\\]\\.person.id, comments\\[\\d+\\]\\.person.showName," +
		"comments\\[\\d+\\]\\.handin, comments\\[\\d+\\]\\.handin.id"}),
		@Result(name = "input", type = "json") })
public class GetHomeworkCommentsAction extends BaseAction {

	private static final long serialVersionUID = 6672605200829697668L;

	private long handid = 0L;

	private boolean success = false;

	private List<HomeworkComment> comments = new ArrayList<HomeworkComment>();

	public String execute() {

		if (0L == handid) {
			return SUCCESS;
		}

		HomeworkHandin handin = HomeworkHandin.get(HomeworkHandin.class, handid);

		if (null == handin) {
			return SUCCESS;
		}

		comments.addAll(this.gradApplication.commentsOfHomeworkhandins(pagerOf(HomeworkComment.class, " where o.handin.id = " + handid),
				handin, getRepository()));

		success = true;

		return SUCCESS;
	}

	public long getHandid() {
		return handid;
	}

	public void setHandid(long handid) {
		this.handid = handid;
	}

	public boolean isSuccess() {
		return success;
	}

	public List<HomeworkComment> getComments() {
		return comments;
	}

}
